package com.zyf.project.kvdb.protocol.proto;

import com.zyf.project.binaryproto.annotation.DataContract;
import com.zyf.project.binaryproto.annotation.DataField;
import com.zyf.project.binaryproto.type.PrimitiveType;
import com.zyf.project.kvdb.protocol.constants.Constants;
import com.zyf.project.kvdb.protocol.exception.KVDBException;
import com.zyf.project.kvdb.protocol.uri.KVDBURI;

/**
 * <h1>集群配置</h1>
 *
 * @author Zhou Yifan
 */
@DataContract(code = Constants.CLUSTER_INFO)
public interface ClusterInfo {

    /**
     * 获取集群大小
     * @return int 值
     */
    @DataField(order = 1, primitiveType = PrimitiveType.INT32)
    int size();

    /**
     * 获取集群配置项
     * @return {@link ClusterItem} 数组
     */
    @DataField(order = 2, list = true, refContract = true)
    ClusterItem[] getClusterItems();

    /**
     * 匹配集群配置
     *
     * @param localPort         本地端口
     * @param remoteURI         远程连接 URI
     * @param remoteClusterInfo 远程连接集群 URI
     * @return 布尔值
     */
    boolean match(int localPort, KVDBURI remoteURI, ClusterInfo remoteClusterInfo) throws KVDBException;

}
